package ch03.shiLi;

import ch03.shiLi.dao.NewsDao;
import ch03.shiLi.dao.impl.NewsDaoMySqlImpl;
import ch03.shiLi.dao.impl.NewsDaoOracleImpl;
import ch03.shiLi.dao.impl.NewsDaoRedisImpl;

//创建NewDAO实例的工厂类
public class SimpleDaoFactory {
//    示例1
    /**
     * 创建NewDAO实例的工厂方法
     * @return
     */
    public static NewsDao getInstance(String key){
        switch (key){
            case "mysql":
                return new NewsDaoMySqlImpl();
            case "oracle":
                return new NewsDaoOracleImpl();
            case "redis":
                return new NewsDaoRedisImpl();
            default:
                throw new RuntimeException("无效的数据库类型："+key+"Dao获取失败");
        }
    }


}
